package se.webbzon.boltzmann.game.object.dialogue;

import se.webbzon.boltzmann.resource.Resources;
import se.webbzon.oschi01.worldobject.appearance.Animation3D;
import se.webbzon.oschi01.worldobject.appearance.Appearance3D;
import se.webbzon.oschi01.worldobject.appearance.SimpleAppearance3D;
import se.webbzon.oschi01.worldobject.appearance.XYPlaneAppearance3D;

public class DialogueCircle extends  AbstractDialogueItem {
		
	// The phase value
	private double t;
	
	// The maximal size of the circle
	private final double maxSize;
		
	/*============================================================
	Constructors
	============================================================*/
		
	/** Creates a new dialogue circle. **/
	public DialogueCircle(double maxSize) {
		super(createAppearance());
		this.maxSize = maxSize;
		t = 0;

		setSize(0, 0, 1);
		getAppearance().setAnimation(new CircleAnimation());
	}
		
	/*============================================================
	Public Methods
	============================================================*/
		
	@Override public void display() {
		super.display();
		t = 0;
		setSize(0,0,1);
	}
	
	/*============================================================
	Private Methods
	============================================================*/
	
	/** Creates the appearance of this dialogue circle. **/
	private static final Appearance3D createAppearance() {
		XYPlaneAppearance3D appearance = 
				new XYPlaneAppearance3D(0,
										SimpleAppearance3D.TRANSPARENCY+
										SimpleAppearance3D.LAYERS, false);
		appearance.setTextureSet(Resources.getTextureSet("misc_dialogue_circle"));
		appearance.setLayer(0, 0, 1);

		return appearance;
	}
	
	/*============================================================
	Private Classes
	============================================================*/
	
	private final class CircleAnimation implements Animation3D {

		@Override public void onStepEnd(Appearance3D appearance) {
			if (!isHidden()) {
				t += Math.PI/45;
				setSize(Math.sin(t)*maxSize,Math.sin(t)*maxSize,1);
			}
		}
		
	}
}
